﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="tree.aspx.cs" Inherits="hcms.Admin.tree" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
	<title>HCMS Admin Tree</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<link href="Styles/leftframe.css" rel="stylesheet" type="text/css" />
	<script src="/Scripts/jquery.min.161.js" type="text/javascript"></script>
	<script src="js/jquery-ui.custom.min.187.js" type="text/javascript"></script>
	<script src="/Scripts/jquery.cookie.js" type="text/javascript"></script>
	<link href="js/skin-vista/ui.dynatree.css" rel="stylesheet" type="text/css"
		id="skinSheet" />
	<script src="js/jquery.dynatree.js" type="text/javascript"></script>
	<!-- (Irrelevant source removed.) -->
	<script type="text/javascript">

		var noView = false;	// if noView = true, will not exe the onActivate envt.

		// 页面载入时执行
		$(function () {
			//==== 初始化树
			$("#tree").dynatree({
				checkbox: true, 
				selectMode: 2, 
				children: <%=treedata %>,	// 初始树
				autoFocus: true,	// 点击左边的展开收回图标时不选择当前项
				clickFolderMode: 1,	// 1:activate, 2:expand, 3:activate and expand  1：点击某项文字时不展开或收回子树，仅选择该项
				onActivate: function (node) {
				//onClick: function (node) {
					if( noView )
						return; // if noView is true, return;

					// A DynaTreeNode object is passed to the activation handler 
					// Note: we also get this event, if persistence is on, and the page is reloaded. 
					if (node.data.url) {	// 有url时直接打开
						window.parent.setSrc(node.data.url, node.data.urlopen);
					}
					else if( node.data.column )	// 栏目时转到对应的栏目页
					{
						window.parent.setSrc( "ColumnList.aspx?cid=" + node.data.key );
						// 清除全部勾选
						$("#tree").dynatree("getRoot").visit(function(node){node.select(false);});
					}
				},
				onLazyRead: function (node) {
					node.appendAjax({ url: "tree.aspx?ajaxcmd=extendnode&key=" + node.data.key});
				}
			});
		});

		function setSelects(cids) {
			// 清除全部
			$("#tree").dynatree("getRoot").visit(function(node){node.select(false);});

			// 选择栏目
			var arr = cids.split(',');
			var n = arr.length;
			for (var i = 0; i < n; i++) {
				if( arr[i] == "" )
					continue;	// 打开被另一个用户删除的文档、栏目、模板可能会出现 n = 1, arr[0] = "";
				$("#tree").dynatree("getTree").selectKey(arr[i]);
				var node = $("#tree").dynatree("getTree").getNodeByKey(arr[i]);
				node.makeVisible() 
				//node.expand(true);
			}

		}

		function getSelects() {
			var selNodes = $("#tree").dynatree("getTree").getSelectedNodes(); 
			// convert to title/key array 
			var selKeys = $.map(selNodes, function(node){ 
				 return node.data.key; 
			});
			return selKeys;
		}

		function setActive( cid )
		{
			noView = true;	// 从这里激活的，不执行onActive事件
			$("#tree").dynatree("getTree").activateKey(cid);
			noView = false;
		}
		
		// 注销
		function logout() {
			//this.disabled = true; // 防止重复提交

			try {
				var prompts = {
					logout: true
				};
				$.post('/Ajax.aspx', prompts, function (data) {
					if (data == "OK") {
						window.parent.window.location = "/";
					}
					else
						alert(data);

					//this.disabled = false;
				});

			}
			catch (err) {
				alert(err.message);
				//this.disabled = false;
			}
		}
	</script>
	<!-- (Irrelevant source removed.) -->
</head>
<body>
	<form id="form1" runat="server">
	<div id="treelogo">HCMS Admin <span class="ver">V0.5</span></div>
	<div id="treeuser">当前用户: <span id="username" runat="server"></span>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:logout();">退出</a></div>
	<div id="tree">
	</div>
	</form>
</body>
</html>
